package cn.hxth.cloud.provider.controller;

import cn.hxth.cloud.api.domain.ProductionOrder;
import cn.hxth.cloud.api.domain.Turnoff;
import cn.hxth.cloud.provider.service.ProductionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

@RestController
@RequestMapping("/production/")
public class ProductionController {
    private Logger logger = LoggerFactory.getLogger(ProductionController.class) ;
    @Resource
    private ProductionService productionService ;
    @PostMapping("insertProductionOrder")
    public Boolean insertProductionOrder(@RequestBody ProductionOrder[] productionOrders, @RequestParam("mid") String mid){
        try {
            return this.productionService.insertProductionOrder(Arrays.asList(productionOrders),mid) ;
        } catch (Exception e) {
           logger.error("error",e);
           return  false ;
        }

    }
    @PutMapping("startProducing")
    public Boolean startProducing(@RequestParam("id") Long id){
        return  this.productionService.startProducing(id) ;
    }
    @PutMapping("doNext")
    public Boolean doNext(@RequestParam("id") Long id){
        return  this.productionService.doNext(id) ;
    }
    @PutMapping("updateStatus")
    public Boolean updateStatus(@RequestBody ProductionOrder productionOrder){
        return  this.productionService.updateStatus(productionOrder) ;
    }
    @PutMapping
    public void insertTurnoff(@RequestParam("id") Long id, Turnoff[] turnoffs){
        this.productionService.insertTurnoff(id,Arrays.asList(turnoffs));
    }
}
